package com.dstz.bpm.engine.model;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.dstz.base.core.util.StringUtil;
import com.dstz.bpm.api.constant.NodeType;
import com.dstz.bpm.api.engine.plugin.context.BpmPluginContext;
import com.dstz.bpm.api.model.def.BpmDataModel;
import com.dstz.bpm.api.model.def.BpmDefProperties;
import com.dstz.bpm.api.model.def.BpmProcessDef;
import com.dstz.bpm.api.model.def.BpmVariableDef;
import com.dstz.bpm.api.model.def.NodeInit;
import com.dstz.bpm.api.model.form.BpmForm;
import com.dstz.bpm.api.model.nodedef.BpmNodeDef;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class DefaultBpmProcessDef implements BpmProcessDef {
   private static final long serialVersionUID = 1L;
   private String F = "";
   private String name = "";
   private String processDefinitionId = "";
   private List<BpmNodeDef> bg;
   private BpmProcessDef bh = null;
   private List<BpmPluginContext> bi = new ArrayList();
   private List<BpmVariableDef> bj = new ArrayList();
   private List<BpmDataModel> bk = new ArrayList();
   private BpmForm bl = null;
   private BpmForm bm = null;
   private BpmForm bn = null;
   private BpmForm bo = null;
   private BpmDefProperties bp = new BpmDefProperties();
   private List<NodeInit> bq = new ArrayList();
   private JSONObject br;

   public BpmProcessDef getParentProcessDef() {
      return this.bh;
   }

   public BpmDefProperties getExtProperties() {
      return this.bp;
   }

   public void setExtProperties(BpmDefProperties extPropertys) {
      this.bp = extPropertys;
   }

   public List<BpmPluginContext> getBpmPluginContexts() {
      return this.bi;
   }

   public BpmPluginContext a(Class<?> clazz) {
      List<BpmPluginContext> Plugins = this.getBpmPluginContexts();
      if (CollectionUtil.isEmpty(Plugins)) {
         return null;
      } else {
         Iterator var3 = Plugins.iterator();

         BpmPluginContext pulgin;
         do {
            if (!var3.hasNext()) {
               return null;
            }

            pulgin = (BpmPluginContext)var3.next();
         } while(!pulgin.getClass().isAssignableFrom(clazz));

         return pulgin;
      }
   }

   public List<BpmVariableDef> getVariableList() {
      return this.bj;
   }

   public BpmForm getInstForm() {
      return this.bl;
   }

   public BpmForm getInstMobileForm() {
      return this.bm;
   }

   public BpmForm getGlobalForm() {
      return this.bn;
   }

   public BpmForm getGlobalMobileForm() {
      return this.bo;
   }

   public List<BpmPluginContext> getPluginContextList() {
      return this.bi;
   }

   public void setPluginContextList(List<BpmPluginContext> pluginContextList) {
      Collections.sort(pluginContextList);
      this.bi = pluginContextList;
   }

   public List<BpmVariableDef> getVarList() {
      return this.bj;
   }

   public void setVarList(List<BpmVariableDef> varList) {
      this.bj = varList;
   }

   public void setInstForm(BpmForm instForm) {
      this.bl = instForm;
   }

   public void setInstMobileForm(BpmForm instMobileForm) {
      this.bm = instMobileForm;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getName() {
      return this.name;
   }

   public void setGlobalForm(BpmForm globalForm) {
      this.bn = globalForm;
   }

   public void setGlobalMobileForm(BpmForm globalMobileForm) {
      this.bo = globalMobileForm;
   }

   public String getDefKey() {
      return this.F;
   }

   public void setDefKey(String defKey) {
      this.F = defKey;
   }

   public void setProcessDefinitionId(String processDefinitionId) {
      this.processDefinitionId = processDefinitionId;
   }

   public String getProcessDefinitionId() {
      return this.processDefinitionId;
   }

   public void setBpmnNodeDefs(List<BpmNodeDef> bpmnNodeDefs) {
      this.bg = bpmnNodeDefs;
   }

   public List<BpmNodeDef> getBpmnNodeDefs() {
      return this.bg;
   }

   public BpmNodeDef getBpmnNodeDef(String nodeId) {
      Iterator var2 = this.bg.iterator();

      BpmNodeDef nodeDef;
      do {
         if (!var2.hasNext()) {
            return null;
         }

         nodeDef = (BpmNodeDef)var2.next();
      } while(!nodeId.equals(nodeDef.getNodeId()));

      return nodeDef;
   }

   public BpmNodeDef getStartEvent() {
      Iterator var1 = this.bg.iterator();

      BpmNodeDef nodeDef;
      do {
         if (!var1.hasNext()) {
            return null;
         }

         nodeDef = (BpmNodeDef)var1.next();
      } while(!nodeDef.getType().equals(NodeType.START));

      return nodeDef;
   }

   public List<NodeInit> getNodeInitList() {
      return this.bq;
   }

   public List<NodeInit> d(String nodeId) {
      List<NodeInit> initList = new ArrayList();
      Iterator var3 = this.bq.iterator();

      while(var3.hasNext()) {
         NodeInit init = (NodeInit)var3.next();
         if (StringUtil.isNotEmpty(nodeId) && init.getNodeId().equals(nodeId)) {
            initList.add(init);
         }
      }

      return initList;
   }

   public void setNodeInitList(List<NodeInit> nodeInitList) {
      this.bq = nodeInitList;
   }

   public List<BpmNodeDef> getStartNodes() {
      BpmNodeDef startNode = this.getStartEvent();
      return startNode == null ? null : startNode.getOutcomeNodes();
   }

   public List<BpmNodeDef> getEndEvents() {
      List<BpmNodeDef> rtnList = new ArrayList();
      Iterator var2 = this.bg.iterator();

      while(var2.hasNext()) {
         BpmNodeDef nodeDef = (BpmNodeDef)var2.next();
         if (nodeDef.getType().equals(NodeType.END)) {
            rtnList.add(nodeDef);
         }
      }

      return rtnList;
   }

   public List<BpmDataModel> getDataModelList() {
      return this.bk;
   }

   public String getDataModelKeys() {
      List<String> keys = new ArrayList();
      Iterator var2 = this.bk.iterator();

      while(var2.hasNext()) {
         BpmDataModel model = (BpmDataModel)var2.next();
         keys.add(model.getCode());
      }

      return keys.isEmpty() ? null : StringUtil.join(keys);
   }

   public void setDataModelList(List<BpmDataModel> dataModelList) {
      this.bk = dataModelList;
   }

   public void setParentProcessDef(DefaultBpmProcessDef processDef) {
      this.bh = processDef;
   }

   public void setJson(JSONObject bpmDefSetting) {
      this.br = bpmDefSetting;
   }

   public JSONObject getJson() {
      return this.br;
   }
}
